import * as actionTypes from './constants'
import { Map } from "immutable";

const defaultState = Map({
  // 播放列表
  playList: [],
  currentSongIndex: 0, // 对应的索引值
  currentSong: {},
  sequence: 0, // 0->循环 1->随机 2->单曲
  lyricList: [], //歌词数据
  currentLyricIndex: 0,
})

function reducer( state = defaultState, action){
  switch(action.type) {
    case actionTypes.CHANGE_CURRENT_SONG:
      return state.set("currentSong", action.currentSong)
    case actionTypes.CHANGE_PLAY_LIST:
      return state.set("playList", action.playList)
    case actionTypes.CHANGE_CURRENT_SONG_INDEX:
      return state.set("currentSongIndex", action.index)
    case actionTypes.CHANGE_SEQUENCE:
      return state.set("sequence", action.sequence)
    case actionTypes.CHANGE_LYRIC_LIST:
      return state.set("lyricList", action.lyricList)
    case actionTypes.CHANGE_CURRENT_LYRIC_INDEX:
      return state.set("currentLyricIndex", action.currentLyricIndex)
    default:
      return state;
  }
}

export default reducer